package com.dab.chat.session;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dab.chat.utils.ChatHelper;
import com.dab.chat.R;
import com.dab.chat.bean.SessionListBean;
import com.dab.chat.interfaces.LoadSession;

import java.util.List;

/**
 * Created by dab on 2018/3/10 13:03
 */

public class SessionListFragment extends Fragment {

    private RecyclerView mSessionList;
    private SessionListAdapter mSessionListAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.chat_fragment_session_list, container, false);
        initView(inflate);
        initData();
        initEvent();
        return inflate;
    }


    private void initData() {
        ChatHelper.getInstance().loadSessionList(new LoadSession() {
            @Override
            public void loadSession(List<SessionListBean> sessionListBeans) {
                mSessionListAdapter.setSessionListBeans(sessionListBeans);
            }
        });
    }

    private void initView(View inflate) {
        mSessionList = inflate.findViewById(R.id.rv_chat_session_list);
        mSessionList.setLayoutManager(new LinearLayoutManager(getActivity()));
        mSessionListAdapter = new SessionListAdapter();
        mSessionList.setAdapter(mSessionListAdapter);
    }

    private void initEvent() {

    }
}
